package com.fjut.kms.dao;

import com.fjut.kms.tools.DBTools;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by Empathy on 2017/8/7.
 */
public class UserDepartmentJDBCImpl implements UserDepartmentDao {
    private static final String SQL_GET_DEPTNAME="select deptName from departments where deptName=?";
    public String getDeptNameByDeptName(String deptName){
        Connection conn= DBTools.getConn();
        PreparedStatement pstmt=null;
        ResultSet rset =null;
        String result=null;
        try{
            pstmt = conn.prepareStatement(SQL_GET_DEPTNAME);
            pstmt.setString(1,deptName);
            rset=pstmt.executeQuery(); 
            if (rset.next()){
                result=rset.getString("deptName");
            }
        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            DBTools.releaseRes(conn,pstmt,null);
        }
        return result;
    }
}
